var api = require('../../utils/api.js')

Page({
    data: {
        list: [],
        infos:[],
        start_t:'',
        end_t:''
    },
    onLoad() {
   
    

    },

    seelist1(ret){
        console.log(ret);

        var i=ret.currentTarget.dataset.i;

        wx.navigateTo({
          url: '/pages/list/index1?id='+i
        })

    },

    getdatainfo(){

        var statrtime=this.data.start_t;
        var endtime=this.data.end_t;
        var that=this;

        api.post({
            url: 'ranking/getalldatebytime',
            data: {statrtime:statrtime,endtime:endtime},
            success: data => {
                that.setData({
                    infos:data.data
                })
            }
        });

    },

    onShow() {

        let user = wx.getStorageSync('userinfo');
        if (!user) {
            wx.redirectTo({
                url: '/pages/login/login'
            });
        }

        this.setData({
            user:user,
            imgs:user.avatar
        })

        api.post({
            url: 'ranking/gettodaydate',
            data: {},
            success: data => {
                this.setData({
                    start_t:data.data.a,
                    end_t:data.data.b
                })

                this.getdatainfo();
            }
        });

        api.get({
            url: 'user/index',
            data: {},
            success: data => {
                this.setData({
                    user:data.data,
                    imgs:data.data.avatar
                })
            }
        });

    },

    getqrcode(){
        api.get({
            url: 'wxapp/Getqrcode/getqrcode',
            data: {},
            success: data => {
                console.log(data.data);
            }
        });

    },

    getimgs(){
        let that = this;
        var usrl=api.HOST;

        wx.chooseImage({
          count: 1,
          sizeType: ['compressed'], // 可以指定是原图还是压缩图，默认二者都有
          sourceType: ['album', 'camera'], // 可以指定来源是相册还是相机，默认二者都有
          success: function (res) {
            console.log(res)
      
            // 返回选定照片的本地文件路径列表，tempFilePath可以作为img标签的src属性显示图片
            let tempFilePaths = res.tempFilePaths;
         
            wx.uploadFile({
              filePath: tempFilePaths[0],
              name: 'file',
              url: usrl+'/api/common/upload',
              formData:{},
              success:function(res){
                var data= JSON.parse(res.data);
                var imgs=data.data.fullurl;
                that.setData({
                  imgs:data.data.fullurl
                });

                api.get({
                    url: 'user/setimg',
                    data: {imgs:imgs},
                    success: data => {
                        console.log(data.data);
                    }
                });


        
              },
              fail: function (res) {
                console.log('上传失败');
                }
            })
          }
        })
    },

    addclient(){
        wx.navigateTo({
          url: '/pages/list/add',
        })
    },
    seeranking(){
        wx.navigateTo({
            url: '/pages/my/ranking',
          })
    },
    seedata(){
        wx.navigateTo({
            url: '/pages/my/data',
          })
    },
    feedback(){
        wx.navigateTo({
            url: '/pages/my/feedback',
          })
    },
    seeboss1(){
        wx.navigateTo({
            url: '/pages/boss/index',
          })
    },
    seeboss2(){
        wx.navigateTo({
            url: '/pages/boss/index1',
          })
    },
    seeboss3(){
        wx.navigateTo({
            url: '/pages/boss/index2',
          })
    },
    seerule(){
        wx.navigateTo({
            url: '/pages/rule/index',
          })

    },
    goexit(){
        wx.setStorageSync('token', '');
        wx.setStorageSync('userinfo', '');

        wx.navigateTo({
          url: '/pages/login/login'
        })

    }

});